<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="utf-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <meta name="description" content="">
        <meta name="author" content="">
        <title>
            jQuery Calx 2.2.7 Sample
        </title>
        <link href="css/bootstrap.css" rel="stylesheet" type="text/css">
        <link href="css/sb-admin.css" rel="stylesheet" type="text/css">
        <link href="css/style.css" rel="stylesheet" type="text/css">
        <link rel="stylesheet" href="font-awesome/css/font-awesome.min.css" type="text/css">
    </head>
    <body>
        <div id="wrapper">
            <nav class="navbar navbar-inverse navbar-fixed-top" role="navigation">
                <div class="navbar-header">
                    <button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-ex1-collapse">
                        <span class="sr-only">Toggle navigation</span>
                    </button>
                    <a class="navbar-brand" href="#">jQuery Calx 2.2.7 Sample</a>
                </div>
                <div class="collapse navbar-collapse navbar-ex1-collapse">
                    <ul class="nav navbar-nav side-nav">
                        <li><a href="#">Index</a></li>
                        <li><a href="basic.html">Basic Calculation</a></li>
                        <li><a href="dynamic_form.html">Dynamic Form</a></li>
                        <li><a href="checkbox.html">Cehckbox, Radio, and Select</a></li>
                        <li class="active"><a href="chart.html">Drawing Chart</a></li>
                        <li><a href="multisheet.html">Multiple Sheet</a></li>
                        <li><a href="formula.html">Formula Showcase</a></li>
                        <li><a href="server_side.html">Server Side Formula</a></li>
                        <li class="dropdown">
                            <a data-toggle="dropdown" class="dropdown-toggle" href="#">
                                Sample Application
                                <b class="caret"></b>
                            </a>
                            <ul class="dropdown-menu">
                                <li><a href="app/budget_planner.html">Budget Planner</a></li>
                                <li><a href="app/amortization_schedule.html">Amortization Schedule</a></li>
                                <li><a href="app/home_mortgage.html">Home Mortgage Calc</a></li>
                                <li><a href="app/home_expense.html">Home Expense Calc</a></li>
                            </ul>
                        </li>

                    </ul>
                </div>
            </nav>
            <div id="page-wrapper">
                <form action="" id="sheet1">
                    <div class="row">
                        <div class="col-lg-10">
                            <h2>Drawing Chart with jQuery Calx</h2>
                        </div>
                        <div class="col-lg-2">
                            <button class="btn btn-primary pull-right" id="show_formula" data-shown="0">Show Formula</button>
                        </div>
                    </div>
                    <hr>
                    <div class="row">
                        <div class="col-md-12">
                            <table class="table table-stripped table-condensed">
                                <thead>
                                    <tr>
                                        <td class="chead">&nbsp;</td>
                                        <td class="text-center chead">A</td>
                                        <td class="text-center chead">B</td>
                                        <td class="text-center chead">C</td>
                                        <td class="text-center chead">D</td>
                                        <td class="text-center chead">E</td>
                                        <td class="text-center chead">F</td>
                                        <td class="text-center chead">G</td>
                                        <td class="text-center chead">H</td>
                                        <td class="text-center chead">I</td>
                                        <td class="text-center chead">J</td>
                                    </tr>
                                </thead>
                                <tbody>
                                    <tr>
                                        <td class="rhead">1</td>
                                        <td><input class="form-control input-sm" data-cell="A1"></td>
                                        <td><input class="form-control input-sm" data-cell="B1" value="USA"></td>
                                        <td><input class="form-control input-sm" data-cell="C1" value="Canada"></td>
                                        <td><input class="form-control input-sm" data-cell="D1" value="China"></td>
                                        <td><input class="form-control input-sm" data-cell="E1" value="Russia"></td>
                                        <td><input class="form-control input-sm" data-cell="F1" value="Asia"></td>
                                        <td><input class="form-control input-sm" data-cell="G1" value="Europe"></td>
                                        <td><input class="form-control input-sm" data-cell="H1" value="Africa"></td>
                                        <td><input class="form-control input-sm" data-cell="I1" value="Australia"></td>
                                        <td><input class="form-control input-sm" data-cell="J1" value="South America"></td>
                                    </tr>
                                    <tr>
                                        <td class="rhead">2</td>
                                        <td><input class="form-control input-sm" data-cell="A2" value="2002"></td>
                                        <td><input class="form-control input-sm" data-cell="B2" data-format="0.00"></td>
                                        <td><input class="form-control input-sm" data-cell="C2" data-format="0.00"></td>
                                        <td><input class="form-control input-sm" data-cell="D2" data-format="0.00"></td>
                                        <td><input class="form-control input-sm" data-cell="E2" data-format="0.00"></td>
                                        <td><input class="form-control input-sm" data-cell="F2" data-format="0.00"></td>
                                        <td><input class="form-control input-sm" data-cell="G2" data-format="0.00"></td>
                                        <td><input class="form-control input-sm" data-cell="H2" data-format="0.00"></td>
                                        <td><input class="form-control input-sm" data-cell="I2" data-format="0.00"></td>
                                        <td><input class="form-control input-sm" data-cell="J2" data-format="0.00"></td>
                                    </tr>
                                    <tr>
                                        <td class="rhead">3</td>
                                        <td><input class="form-control input-sm" data-cell="A3" value="2003"></td>
                                        <td><input class="form-control input-sm" data-cell="B3" data-format="0.00"></td>
                                        <td><input class="form-control input-sm" data-cell="C3" data-format="0.00"></td>
                                        <td><input class="form-control input-sm" data-cell="D3" data-format="0.00"></td>
                                        <td><input class="form-control input-sm" data-cell="E3" data-format="0.00"></td>
                                        <td><input class="form-control input-sm" data-cell="F3" data-format="0.00"></td>
                                        <td><input class="form-control input-sm" data-cell="G3" data-format="0.00"></td>
                                        <td><input class="form-control input-sm" data-cell="H3" data-format="0.00"></td>
                                        <td><input class="form-control input-sm" data-cell="I3" data-format="0.00"></td>
                                        <td><input class="form-control input-sm" data-cell="J3" data-format="0.00"></td>
                                    </tr>
                                    <tr>
                                        <td class="rhead">4</td>
                                        <td><input class="form-control input-sm" data-cell="A4" value="2004"></td>
                                        <td><input class="form-control input-sm" data-cell="B4" data-format="0.00"></td>
                                        <td><input class="form-control input-sm" data-cell="C4" data-format="0.00"></td>
                                        <td><input class="form-control input-sm" data-cell="D4" data-format="0.00"></td>
                                        <td><input class="form-control input-sm" data-cell="E4" data-format="0.00"></td>
                                        <td><input class="form-control input-sm" data-cell="F4" data-format="0.00"></td>
                                        <td><input class="form-control input-sm" data-cell="G4" data-format="0.00"></td>
                                        <td><input class="form-control input-sm" data-cell="H4" data-format="0.00"></td>
                                        <td><input class="form-control input-sm" data-cell="I4" data-format="0.00"></td>
                                        <td><input class="form-control input-sm" data-cell="J4" data-format="0.00"></td>
                                    </tr>
                                    <tr>
                                        <td class="rhead">5</td>
                                        <td><input class="form-control input-sm" data-cell="A5" value="2005"></td>
                                        <td><input class="form-control input-sm" data-cell="B5" data-format="0.00"></td>
                                        <td><input class="form-control input-sm" data-cell="C5" data-format="0.00"></td>
                                        <td><input class="form-control input-sm" data-cell="D5" data-format="0.00"></td>
                                        <td><input class="form-control input-sm" data-cell="E5" data-format="0.00"></td>
                                        <td><input class="form-control input-sm" data-cell="F5" data-format="0.00"></td>
                                        <td><input class="form-control input-sm" data-cell="G5" data-format="0.00"></td>
                                        <td><input class="form-control input-sm" data-cell="H5" data-format="0.00"></td>
                                        <td><input class="form-control input-sm" data-cell="I5" data-format="0.00"></td>
                                        <td><input class="form-control input-sm" data-cell="J5" data-format="0.00"></td>
                                    </tr>
                                    <tr>
                                        <td class="rhead">6</td>
                                        <td><input class="form-control input-sm" data-cell="A6" value="2006"></td>
                                        <td><input class="form-control input-sm" data-cell="B6" data-format="0.00"></td>
                                        <td><input class="form-control input-sm" data-cell="C6" data-format="0.00"></td>
                                        <td><input class="form-control input-sm" data-cell="D6" data-format="0.00"></td>
                                        <td><input class="form-control input-sm" data-cell="E6" data-format="0.00"></td>
                                        <td><input class="form-control input-sm" data-cell="F6" data-format="0.00"></td>
                                        <td><input class="form-control input-sm" data-cell="G6" data-format="0.00"></td>
                                        <td><input class="form-control input-sm" data-cell="H6" data-format="0.00"></td>
                                        <td><input class="form-control input-sm" data-cell="I6" data-format="0.00"></td>
                                        <td><input class="form-control input-sm" data-cell="J6" data-format="0.00"></td>
                                    </tr>
                                </tbody>
                                <tfoot>
                                    <tr>
                                        <td colspan="11" class="text-right">
                                            <button class="btn btn-sm btn-primary" id="randomize">Randomize</button>
                                        </td>
                                    </tr>
                                </tfoot>
                            </table>
                        </div>
                    </div>

                    <div class="row">
                        <div class="col-md-4">
                            <div style="width:250px; height:250px;float:left;">
                                <h4 class="text-center" data-formula="CONCAT('Donut Graph ', A2)"></h4>
                                <div data-formula="GRAPH(B2:J2, ['type=donut', 'legend=B1:J1'])" style="width:250px; height:250px;"></div>
                            </div>
                        </div>
                        <div class="col-md-4">
                            <div style="width:250px; height:250px;float:left;">
                                <h4 class="text-center" data-formula="CONCAT('Donut Graph ', A3)"></h4>
                                <div data-formula="GRAPH(B3:J3, ['type=donut', 'legend=B1:J1'])" style="width:250px; height:250px;"></div>
                            </div>
                        </div>
                        <div class="col-md-4">
                            <div style="width:250px; height:250px;float:left;">
                                <h4 class="text-center" data-formula="CONCAT('Donut Graph ', A4)"></h4>
                                <div data-formula="GRAPH(B4:J4, ['type=donut', 'legend=B1:J1'])" style="width:250px; height:250px;"></div>
                            </div>
                        </div>
                    </div>
                    <div class="row" style="margin-top:100px">
                        <div class="col-md-4 col-md-offset-2">
                            <div style="width:250px; height:250px;float:left;">
                                <h4 class="text-center" data-formula="CONCAT('Pie Graph ', A5)"></h4>
                                <div data-formula="GRAPH(B5:J5, ['type=pie', 'legend=B1:J1'])" style="width:250px; height:250px;"></div>
                            </div>
                        </div>
                        <div class="col-md-4">
                            <div style="width:250px; height:250px;float:left;">
                                <h4 class="text-center" data-formula="CONCAT('Pie Graph ', A6)"></h4>
                                <div data-formula="GRAPH(B6:J6, ['type=pie', 'legend=B1:J1'])" style="width:250px; height:250px;"></div>
                            </div>
                        </div>
                    </div>

                    <div class="row" style="margin-top:100px">
                        <div class="col-md-12">
                            <h4 class="text-center">Line Graph</h4>
                            <div data-formula="GRAPH(B2:J6, ['legend=B1:J1', 'label=A2:A6', 'orientation=vertical'])"></div>
                        </div>
                    </div>

                    <div class="row" style="margin-top:100px">
                        <div class="col-md-12">
                            <h4 class="text-center">Bar Graph</h4>
                            <div data-formula="GRAPH(B2:J4, ['type=bar', 'label=B1:J1', 'legend=A2:A4'])"></div>
                        </div>
                    </div>
                </form>
            </div>
        </div>

        <script src="js/jquery-calx-sample-2.2.7.min.js" type="text/javascript"></script>
        <script src="js/bootstrap.js" type="text/javascript"></script>
        <script>
            var calc  = $('#sheet1').calx();
            var sheet = calc.calx('getSheet');
            var range = sheet.getCellRange('B2', 'J6');

            for(var a in range){
                range[a].setValue(Math.random(10, 1000)*100);
                range[a].renderComputedValue();
            }

            sheet.calculate();

            $('#randomize').click(function(e){
                e.preventDefault();
                var range = sheet.getCellRange('B2', 'J6');

                for(var a in range){
                    range[a].setValue(Math.random(10, 1000)*100);
                    range[a].renderComputedValue();
                }

                sheet.calculate();
            });


            $('#show_formula').click(function(e){
                e.preventDefault();

                if($(this).attr('data-shown') == '0'){
                    $('[data-formula],[data-cell]').each(function(){
                        $(this).after('<span class="formula">'+$(this).attr('data-cell')+($(this).attr('data-formula') ? ' = '+$(this).attr('data-formula') : '')+'&nbsp;</span>');
                    });

                    $(this).attr('data-shown', 1).html('Hide Formula');
                }else{
                    $('span.formula').remove();
                    $(this).attr('data-shown', 0).html('Show Formula');
                }
            });
        </script>
    </body>
</html>